package com.unionpay.upyzt.spring.example.config;

import com.unionpay.upyzt.Upyzt;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author yf.zhao
 * @version 1.0
 * @since 2020/8/27
 */
public class UpyztCustomizer implements InitializingBean {

    private UpyztProperties upyztProperties;

    public UpyztCustomizer(UpyztProperties upyztProperties) {
        this.upyztProperties = upyztProperties;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        // （必填）设置平台商户 Id
        Upyzt.setRootMchId(upyztProperties.getRootMchId());
        // （必填）设置签名私钥路径，用于请求签名
        Upyzt.setSignPrivateKey(upyztProperties.getSignPrivateKey());
        // （必填）设置加密公钥路径，用于敏感字段加密
        Upyzt.setEncryptPublicKey(upyztProperties.getEncryptPublicKey());
        // （可选，推荐设置）设置响应验证公钥，用于验证响应是否真实有效；不设置或设置密钥错误将不验签
        Upyzt.setVerifyPublicKey(upyztProperties.getVerifyPublicKey());
        //
        Upyzt.setApiBase(upyztProperties.getApiBase());
    }
}
